<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>随便打TCS系统</title>
    <script type="text/javascript" src="<%=basePath%>js/initPage.js"></script>
    <!-- Bootstrap -->
    <link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
          rel="stylesheet">
    <!-- Font Awesome -->
    <link
            href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
            rel="stylesheet">
    <!-- NProgress -->
    <link href="<%=basePath%>vendors/nprogress/nprogress.css"
          rel="stylesheet">
    <!-- iCheck -->
    <link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
          rel="stylesheet">

    <!-- bootstrap-progressbar -->
    <link
            href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
            rel="stylesheet">
    <!-- JQVMap -->
    <link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
          rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link
            href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
            rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
</head>
<%@ include file="loginCheck.jsp" %>
<body class="nav-md">
<div class="container body">
    <div class="main_container">
        <div class="col-md-3 left_col">
            <div class="left_col scroll-view">
                <div class="clearfix"></div>
                <br/>
            </div>
        </div>
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                    <div class="row tile_count">
                        <div class="title_left"></div>
                        <div class="x_content">
                            <c:if test="${adminUsergrade == 0}">
                                代理商：<input type="text" id="presentName" value="${presentName}" />
                            </c:if>
                            分享者手机号码：<input type="text" id="userMobile" value="${userMobile}"/>
                            被分享者手机号码：<input type="text" id="presentMobile" value="${presentMobile}"/>
                            <button type="submit" class="btn btn-default"
                                    onclick="selectALL('1')">搜索
                            </button>
                        </div>
                        <div class="clearfix"></div>
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>返利信息</h2>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <p class="text-muted font-13 m-b-30"></p>
                                <table id="datatable"
                                       class="table table-striped table-bordered">
                                    <thead>
                                    <tr>
                                        <th>所属代理商</th>
                                        <th>推荐者手机号</th>
                                        <th>注册者手机号</th>
                                        <c:if test="${type == 1}">
                                            <c:if test="${isLTH != 1}">
                                                <th>赠送通话金额</th>
                                            </c:if>
                                            <th>赠送购物金额</th>
                                        </c:if>
                                        <c:if test="${type == 2}">
                                            <th>在线充值返现金额</th>
                                        </c:if>
                                        <th>分销等级</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${rewardsList}" var="s" varStatus="z">
                                        <tr>
                                            <td>${s.parentid}</td>
                                            <td>${s.userid}</td>
                                            <td>${s.presentid}</td>
                                            <c:if test="${type == 1}">
                                                <c:if test="${isLTH != 1}">
                                                    <td>${s.moneystatus}</td>
                                                </c:if>
                                                <td>${s.shopmoneystatus}</td>
                                            </c:if>
                                            <c:if test="${type == 2}">
                                                <td>${s.integral}</td>
                                            </c:if>
                                            <td>${s.level}</td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <br/>
                    </div>
                    <div style="width: 100%; text-align: center;">
                        <div id='page'></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    /**
     * 纯粹的JS分页插件，代码缺点：JS操作DOM冗余太多，太繁琐
     */
    pageUtil.initPage('page', {
        totalCount: ${pages.recordTotal}, //总页数，一般从回调函数中获取。如果没有数据则默认为1页
        curPage: ${pages.currentPageNo}, //初始化时的默认选中页，默认第一页。如果所填范围溢出或者非数字或者数字字符串，则默认第一页
        showCount: 9, //分页栏显示的数量
        pageSizeList: [10], //自定义分页数，默认[5,10,15,20,50]
        defaultPageSize: 10, //默认选中的分页数,默认选中第一个。如果未匹配到数组或者默认数组中，则也为第一个
        isJump: true, //是否包含跳转功能，默认false
        isPageNum: true, //是否显示分页下拉选择，默认false
        isPN: true, //是否显示上一页和下一面，默认true
        isFL: true, //是否显示首页和末页，默认true
        jump: function (curPage) { //跳转功能回调，传递回来2个参数，当前页和每页大小。如果没有设置分页下拉，则第二个参数永远为0。这里的this被指定为一个空对象，如果回调中需用到this请自行使用bind方法
            selectALL(curPage);
        },
    });
</script>
<script type="text/javascript">
    function selectALL(curPage) {
        var userMobile = $("#userMobile").val();
        var partten = /^(((13[0-9]{1})|(14[579]{1})|(15[^4,\D]{1})|(16[6]{1})|(18[0-9]{1})|(17[^249,\D]{1})|(19[89]{1}))+\d{8})$/;
        if (userMobile.length != 0 && !partten.test(userMobile)) {
            alert('请输入正确的手机号码');
            return false;
        }
        var presentMobile = $("#presentMobile").val();
        if (presentMobile.length != 0 && !partten.test(presentMobile)) {
            alert('请输入正确的手机号码');
            return false;
        }
        var userMobile = $("#userMobile").val();
        var presentMobile = $("#presentMobile").val();
        var presentName = $("#presentName").val();
        $.ajax({
            type: 'POST',
            url: 'beanName',
            data: {
                presentMobile: presentMobile,
                userMobile: userMobile
            },
            success: function (date) {
                switch (date) {
                    case 0:
                        alert("该应用不存在，请检查输入的应用名称是否正确");
                        break;
                    case 1:
                        alert("该代理商不存在，请检查输入的代理商名称是否正确");
                        break;
                    case 2:
                        alert("该商家不存在，请检查输入的商家名称是否正确");
                        break;
                    default:
                        if (${type} == '1';
                    )
                    {
                        location.href = "shareRewards?type="+${type}+;
                        "&currentPageNo=" + curPage + "&userMobile=" + userMobile
                        + "&presentMobile=" + presentMobile + "&presentName=" + presentName;
                    }
                        if (${type} == '2';
                    )
                    {
                        location.href = "integralRewards?type="+${type}+;
                        "&currentPageNo=" + curPage + "&userMobile=" + userMobile
                        + "&presentMobile=" + presentMobile + "&presentName=" + presentName;
                    }
                        break;
                }
            }
        });
    }
</script>

<!-- jQuery -->
<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
<!-- NProgress -->
<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
<!-- bootstrap-daterangepicker -->
<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
<script
        src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- Chart.js -->
<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>

<!-- Custom Theme Scripts -->
<script src="<%=basePath%>build/js/custom.min.js"></script>
</body>
</html>